import { Component, OnInit } from '@angular/core';
import { ServiceCheckService } from './service-check.service';
import { DataService } from '../../../../services/data.service';

@Component({
  selector: 'app-service-check',
  templateUrl: './service-check.component.html',
  styleUrls: ['./service-check.component.scss'],
  providers: [ServiceCheckService]
})
export class ServiceCheckComponent implements OnInit {
  public serviceCheckInfo: any;
  //保存条目post数据
  public addEntryPostBody: any = {
    // "sWeekly": "",//周报
    // "sMonth": "",//月报
    // "sDaily": "",//季报
    // "sYear": "",//年报
    // "sAchAss": "",//绩效评估报告
    // "sMajorMatters": "",//重大事项
    // "sRemind": "",//净值大幅波动提醒
    // "sStopSituation": "",//终止情况
    // "sLiqReport": "",//清算报告
    // "sConItemTemplate": "1"
  }
  //审核信息
  public sAuditInfo: any;
  //服务条目审核putBody
  public serviceCheckPutBody: any = {
    "nFundNo": "",//产品内码
    "action": ""//2代表审核通过，3代表审核不通过
  };
  constructor(
    public serviceCheckService: ServiceCheckService,
    public dataService: DataService
  ) { }

  ngOnInit() {
    this.getSingleServiceInfo();
  }
  //服务条目审核
  serviceCheck(item) {
    let that = this;
    // console.log("安徽沙哈达哈哈的撒和电话"+this.sAuditInfo)
    if (this.sAuditInfo == ''||this.sAuditInfo == undefined) {
      window['swal']("提示", "审核意见不能为空!", "warning");
    } else {
      window["swal"]({
        title: "注意",
        text: "是否确定审核",
        type: "warning",
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        showCancelButton: true,
        closeOnConfirm: false,
        closeOnCancel: true,
        showLoaderOnConfirm: true
      },
        function (isConfirm) {
          if (isConfirm) {
            that.addEntryPostBody.sAuditOpinion = that.sAuditInfo;
            // console.log(that.addEntryPostBody)
            that.serviceCheckService.check(that.addEntryPostBody, that.serviceCheckInfo.nFundNo, item).subscribe(data => {
              if (data) {
                that.dataService.entryEmitter.emit('serviceCheck');
                window['swal']("提示", "审核完成!", "success");
              }
            })
          }
        })
    }

  }
  //查询-单个服务条目条目内容（根据FundNo）
  getSingleServiceInfo() {
    this.serviceCheckService.getSingleInfo(this.serviceCheckInfo.nFundNo).subscribe(data => {
      if (data) {
        this.addEntryPostBody = data;
        // console.log("----------sdahdjhajd---------------")
        // console.log(data);
      }
    })
  }

}
